<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1> 哈哈哈哈哈123</h1>

<script>
    dbChat = require('./database/dbChat');

    var data = {

    };
    console/log("aaaaaaaaaaaaa");
    /*
        dbChat.queryUser(data)
                //找到了
                .then(function (result) {
                            this.data = result
                            //console.log('333333444');
                            //console.log(this.data);
                            // console.log('33355555');
                            //console.log(connectedSockets);

                            //设置他的状态为:已登录,待协会数据库
                            this.data.hasLogined = true;
                            //不允许重复登陆
                            if (connectedSockets[this.data.userName]) {
                                //昵称已被占用，直接返回 false
                                console.log('昵称已被占用，直接返回 false--' + this.data.userName);

                                socket.emit('userAddingResult', {result: false});
                            }
                            else {
                                //这是登录正确了!
                                var resultOK = {};
                                resultOK.result = true;
                                resultOK.data = this.data;

                                this.data.result = true;
                                socket.emit('userAddingResult', resultOK);

                                //同时广播给所有人,XXX登陆了
                                socket.userID = this.data.userID;
                                socket.userName = this.data.userName;
                                socket.nickname = this.data.nickname;

                                //console.log('分配socket.nickname');
                                // console.log(socket.userName);
                                connectedSockets[socket.userName] = socket;//保存每个socket实例,发私信需要用

                                //加入到 聊天用户列表
                                allUsers.push(this.data);
                                console.log('allUser');
                                console.log(allUsers);
                                socket.broadcast.emit('userAdded', this.data);//广播欢迎新用户,除新用户外都可看到
                                socket.emit('allUser', allUsers);//将所有在线用户发给新用户，让他们也都看到最新列表

                                //活动记录保存到数据库
                                var mLog = {
                                    type: 'welcome',
                                    userID: socket.userID,
                                    userName: socket.userName
                                };
                                var insertLogs = dbChat.insertLog(mLog);
                            }
                        }
                )
                //错了,或者没有找到
                .then(null, function (err) {
                    console.log('444444555');
                    console.log(err);
                    //这是登陆错误
                    // console.log('不存在--' + this.data.userName);
                    socket.emit('userAddingResult', {result: false});
                });
    */
</script>
</body>
</html>
